﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GSMClasses
{

    public class Battery
    {
        //fields
        private string model;
        private float? hoursIdle;
        private float? hoursTalk;
        private BatteryType batteryType;

        //constructors
        public Battery()
        {
        }
        public Battery(BatteryType batteryType)
            : this(batteryType, null)
        {
        }
        public Battery(BatteryType batteryType, string model)
            : this(batteryType, model, null)
        {
        }
        public Battery(BatteryType batteryType, string model, float? hoursIdle)
            : this(batteryType, model, hoursIdle, null)
        {
        }
        public Battery(BatteryType batteryType, string model, float? hoursIdle, float? hoursTalk)
        {
            this.Model = model;
            this.HoursIdle = hoursIdle;
            this.HoursTalk = hoursTalk;
            this.BatteryType = batteryType;
        }

        //properties
        public string Model
        {
            get { return this.model; }
            set { this.model = value; }
        }
        public float? HoursIdle
        {
            get { return this.hoursIdle; }
            set
            {
                if (value >= 0 || value == null)
                {
                    this.hoursIdle = value;
                }
                else
                {
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
        public float? HoursTalk
        {
            get { return this.hoursTalk; }
            set
            {
                if (value >= 0 || value == null)
                {
                    this.hoursTalk = value;
                }
                else
                {
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
        public BatteryType BatteryType
        {
            get { return this.batteryType; }
            set
            {
                this.batteryType = value;
            }
        }

        //methods
        public override string ToString()
        {
            StringBuilder infoText = new StringBuilder();
            if (model != null)
            {
                infoText.Append("battery model:");
                infoText.AppendLine(this.model);
            }
            if (hoursIdle != null)
            {
                infoText.Append("battery hours idle:");
                infoText.AppendLine(this.hoursIdle.ToString());
            }
            if (hoursTalk != null)
            {
                infoText.Append("battery hours talk:");
                infoText.AppendLine(this.hoursTalk.ToString());
            }
            if (batteryType != null)
            {
                infoText.Append("battery type:");
                infoText.AppendLine(this.batteryType.ToString());
            }
            return infoText.ToString();
        }

    }
}
